package com.jmb.lease.custom.converter;

import com.jmb.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;


public class StringToItemTypeConverter implements Converter<String, ItemType> {
    @Override
    public ItemType convert(String code) {
        // 我们这个地方直接使用反射方法获取枚举
        ItemType[] enumConstants = ItemType.class.getEnumConstants();
        for (ItemType itemType : enumConstants) {
            if (itemType.getCode().equals(Integer.valueOf(code))){
                return itemType;
            }
        }
        throw new IllegalArgumentException("code"+code+"不存在");
    }
}
